package com.leo.datastruct.sort;

/**
 *
 * @author xuexiaolei
 * @version 2018年02月02日
 */
public class SelectionSort extends Sortable {

    public SelectionSort(String sortMethodName) {
        super(sortMethodName);
    }

    @Override
    public void sort(int[] s) {
        for (int i = 0; i < s.length-1; i++) {
            int selectedIndex = i;
            for (int j = i+1; j < s.length; j++) {
                if (s[j] < s[selectedIndex]) {selectedIndex = j;}
            }
            swap(s, i, selectedIndex);
        }
    }

    public static void main(String[] args) {
        Sortable a = new SelectionSort("简单选择排序");
        a.testSort(new int[]{49,38,65,97,76,13,27,49,78,34,12,64,1});
    }
}
